package org.huangrui.javase;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @Author hr
 * @Create 2025-11-01 16:18
 **/
public class T03IteratorRemove {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(11);
        list.add(12);
        list.add(13);
        list.add(14);
        list.add(15);
        Iterator<Integer> iterator = list.iterator();
        while (iterator.hasNext()) {
            Integer value = iterator.next();
            if (value == 12) {
                // list.remove(value);// Exception in thread "main" java.util.ConcurrentModificationException
                iterator.remove();
            }
        }
        list.forEach(System.out::println);
    }
}
